home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / internet / ghostzilla / ghsetup.exe / chrome / comm.jar / content / editor / EdLabelProps.js < prev    next >
Encoding:
JavaScript  |  2002-04-09  |  4.1 KB  |  136 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Label Properties Dialog.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Neil Rashbrook.
  18.  * Portions created by the Initial Developer are Copyright (C) 2001
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s): Neil Rashbrook <neil@parkwaycc.co.uk>
  22.  *
  23.  * Alternatively, the contents of this file may be used under the terms of
  24.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  25.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26.  * in which case the provisions of the GPL or the LGPL are applicable instead
  27.  * of those above. If you wish to allow use of your version of this file only
  28.  * under the terms of either the GPL or the LGPL, and not to allow others to
  29.  * use your version of this file under the terms of the MPL, indicate your
  30.  * decision by deleting the provisions above and replace them with the notice
  31.  * and other provisions required by the GPL or the LGPL. If you do not delete
  32.  * the provisions above, a recipient may use your version of this file under
  33.  * the terms of any one of the MPL, the GPL or the LGPL.
  34.  *
  35.  * ***** END LICENSE BLOCK ***** */
  36.  
  37. var labelElement;
  38.  
  39. // dialog initialization code
  40.  
  41. function Startup()
  42. {
  43.   if (!InitEditorShell())
  44.     return;
  45.  
  46.   gDialog.editText = document.getElementById("EditText");
  47.   gDialog.labelText = document.getElementById("LabelText");
  48.   gDialog.labelFor = document.getElementById("LabelFor");
  49.   gDialog.labelAccessKey = document.getElementById("LabelAccessKey");
  50.  
  51.   labelElement = window.arguments[0];
  52.  
  53.   // Make a copy to use for AdvancedEdit
  54.   globalElement = labelElement.cloneNode(false);
  55.  
  56.   InitDialog();
  57.  
  58.   editorShell.SelectElement(labelElement);
  59.   gDialog.labelText.value = GetSelectionAsText();
  60.   if (labelElement.innerHTML.match(/</))
  61.   {
  62.     gDialog.editText.checked = false;
  63.     gDialog.editText.disabled = false;
  64.     gDialog.labelText.disabled = true;
  65.     gDialog.editText.addEventListener("command", onEditText, false);
  66.     SetTextboxFocus(gDialog.labelFor);
  67.   }
  68.   else
  69.     SetTextboxFocus(gDialog.labelText);
  70.  
  71.   SetWindowLocation();
  72. }
  73.  
  74. function InitDialog()
  75. {
  76.   gDialog.labelFor.value = globalElement.getAttribute("for");
  77.   gDialog.labelAccessKey.value = globalElement.getAttribute("accesskey");
  78. }
  79.  
  80. function onEditText()
  81. {
  82.   gDialog.editText.removeEventListener("command", onEditText, false);
  83.   AlertWithTitle(GetString("Alert"), GetString("EditTextWarning"));
  84. }
  85.  
  86. function RemoveLabel()
  87. {
  88.   // RemoveTextProperty might work
  89.   // but only because the label was selected to get its text
  90.   RemoveElementKeepingChildren(labelElement);
  91.   SaveWindowLocation();
  92.   window.close();
  93. }
  94.  
  95. function ValidateData()
  96. {
  97.   if (gDialog.labelFor.value)
  98.     globalElement.setAttribute("for", gDialog.labelFor.value);
  99.   else
  100.     globalElement.removeAttribute("for");
  101.   if (gDialog.labelAccessKey.value)
  102.     globalElement.setAttribute("accesskey", gDialog.labelAccessKey.value);
  103.   else
  104.     globalElement.removeAttribute("accesskey");
  105.   return true;
  106. }
  107.  
  108. function onAccept()
  109. {
  110.   // All values are valid - copy to actual element in doc
  111.   ValidateData();
  112.  
  113.   editorShell.BeginBatchChanges();
  114.  
  115.   editorShell.CloneAttributes(labelElement, globalElement);
  116.  
  117.   if (gDialog.editText.checked)
  118.   {
  119.     var editor = editorShell.editor;
  120.     while (labelElement.firstChild)
  121.       editor.deleteNode(labelElement.firstChild);
  122.     if (gDialog.labelText.value) {
  123.       var textNode = editorShell.editorDocument.createTextNode(gDialog.labelText.value);
  124.       editor.insertNode(textNode, labelElement, 0);
  125.       editorShell.SelectElement(labelElement);
  126.     }
  127.   }
  128.  
  129.   editorShell.EndBatchChanges();
  130.  
  131.   SaveWindowLocation();
  132.  
  133.   return true;
  134. }
  135.  
  136.